<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>列表</title>
</head>
<body>

    <div style="margin-left: 30%;margin-top: 5%">
        <div style="margin-left: 21%">
            <input type="button" value="新增" id="add">
        </div>
        <table border="1" cellpadding="3" cellspacing="0" style="margin-top: 1%">
            <thead>
                <tr>
                    <td>id</td>
                    <td>姓名</td>
                    <td>地址</td>
                    <td>电话</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody id="content">

            </tbody>
        </table>
    </div>

<script src="/js/jquery-1.9.1.min.js" type="application/javascript"></script>
<script>
    $(function(){
        resume.init();
    });
    let resume = {

        init:function() {
            resume.queryList();

            $('#add').click(function(){
               window.location = "/resume/addPage";
            });
        },

        queryList:function() {
            $.ajax({
                url:'/resume/getResumes',
                type:'post',
                dataType:'json',
                success:function(data) {
                    if (data.errCode == 200) {
                        let list = data.data;
                        $.each(list, function(index, resume){
                            let html = '<tr>' +
                                            '<td>'+resume.id+'</td>' +
                                            '<td>' + resume.name + '</td>' +
                                            '<td>' + resume.address + '</td>' +
                                            '<td>' + resume.phone + '</td>' +
                                            '<td>'+
                                                "<a href='/resume/updatePage?id="+resume.id+"'>修改</a>&nbsp;"+
                                                "<a data-id="+ resume.id +" href='javascript:void(0);'>删除</a>"+
                                            '</td>'
                                        '</tr>';
                            let $html = $(html);
                            //删除操作
                            $($html).find('a').eq(1).click(function(){
                                $.ajax({
                                   url:'/resume/delete',
                                   type:'post',
                                   dataType:'json',
                                   data:{'id': $($html).find('a').eq(1).attr('data-id')},
                                   success:function(data){
                                       if (data.errCode == 200) {
                                           window.location = '/resume/';
                                       } else {
                                           alert('删除失败');
                                       }
                                   }
                                });
                            });
                           $('#content').append($html);
                        });
                    }
                }
            });
        },

    }

</script>
</body>
</html>
